
#include "CServer.h"


int main()
{
	auto& gCfgMgr = ConfigMgr::Inst();
	std::string gate_port_str = gCfgMgr["GateServer"]["Port"];
	unsigned short gate_port = atoi(gate_port_str.c_str());

	try {
		unsigned short port = static_cast<unsigned short>(gate_port);
		net::io_context ioc{ 1 };
		boost::asio::signal_set signals(ioc, SIGINT, SIGTERM);
		signals.async_wait([&ioc](const boost::system::error_code& error, int signal_number) {
			if (error) {
				return;
			}
			ioc.stop();
		});

		std::make_shared<CServer>(ioc, port)->Start();
		std::cout << "Port: 8080;\nServer is running...\n";
		ioc.run();
	}
	catch (std::exception& exp) {
		std::cout << "Error: " << exp.what() << std::endl;
		return EXIT_FAILURE;
	}

	return 0;
}